fontchooser: Don't cause "row-changed" signal in cell data func
authorBenjamin Otte <otte@redhat.com>
Fri, 12 Jun 2015 19:23:34 +0000 (21:23 +0200)
committerBenjamin Otte <otte@redhat.com>
Fri, 12 Jun 2015 20:04:17 +0000 (22:04 +0200)
The font chooser delays creating the font description from the font face
as long as possible (it's slow). Because we use fixed height mode, we
only have to create font descriptions for rows we are actually going to
show.

This was achieved by looking at the font description column and if it
was NULL, we created a font description and gtk_list_stiore_set() it.
Unfortunately this caused a "row-changed" signal to be emitted and this
emission could happen during the cell data func.
And that caused infinite loops with accessibility when you were unlucky.

This change replaces the NULL font description with an empty one and
instead of setting the correct font description, we
pango_font_description_merge() it in. This way, the list store doesn't
change and no signals are emitted.

https://bugzilla.redhat.com/show_bug.cgi?id=1197267

gtk/gtkfontchooserwidget.c

index 93fa54a8ae0732910627011b72e1019194b7deff..7464f74fe862bea562c2b5d3a8477f28ac75df1d 100644 (file)
@@ -391,34 +391,24 @@ static PangoFontDescription *
 tree_model_get_font_description (GtkTreeModel *model,
                                  GtkTreeIter  *iter)
 {
-  PangoFontDescription *desc;
+  PangoFontDescription *desc, *face_desc;
   PangoFontFace *face;
-  GtkTreeIter child_iter;
 
   gtk_tree_model_get (model, iter,
                       FONT_DESC_COLUMN, &desc,
                       -1);
-  if (desc != NULL)
+  if (pango_font_description_get_set_fields (desc) != 0)
     return desc;
 
   gtk_tree_model_get (model, iter,
                       FACE_COLUMN, &face,
                       -1);
-  desc = pango_font_face_describe (face);
+  face_desc = pango_font_face_describe (face);
   g_object_unref (face);
   
-  if (GTK_IS_TREE_MODEL_FILTER (model))
-    {
-      gtk_tree_model_filter_convert_iter_to_child_iter (GTK_TREE_MODEL_FILTER (model),
-                                                        &child_iter,
-                                                        iter);
-      iter = &child_iter;
-      model = gtk_tree_model_filter_get_model (GTK_TREE_MODEL_FILTER (model));
-    }
+  pango_font_description_merge (desc, face_desc, TRUE);
 
-  gtk_list_store_set (GTK_LIST_STORE (model), iter,
-                      FONT_DESC_COLUMN, desc,
-                      -1);
+  pango_font_description_free (face_desc);
 
   return desc;
 }
@@ -694,19 +684,23 @@ gtk_font_chooser_widget_load_fonts (GtkFontChooserWidget *fontchooser,
 
       for (j = 0; j < n_faces; j++)
         {
+          PangoFontDescription *empty_font_desc;
           const gchar *face_name;
 
           face_name = pango_font_face_get_face_name (faces[j]);
 
           family_and_face = g_strconcat (fam_name, " ", face_name, NULL);
+          empty_font_desc = pango_font_description_new ();
 
           gtk_list_store_insert_with_values (list_store, &iter, -1,
                                              FAMILY_COLUMN, families[i],
                                              FACE_COLUMN, faces[j],
+                                             FONT_DESC_COLUMN, empty_font_desc,
                                              PREVIEW_TITLE_COLUMN, family_and_face,
                                              -1);
 
           g_free (family_and_face);
+          pango_font_description_free (empty_font_desc);
         }
 
       g_free (faces);